#include "Ping.h"
#include "SocketIO.h"
#include <iostream>
#include "string.h"
namespace task {
    int Ping::clientAction(socketinf serverinf, const char * arg, size_t len) {
        // Auto generate
        SocketIO sio(serverinf);

        // IMPORTANT trigger master execute serverAction 
        sio.socketWriter->sendFrame(TaskFlag::ping, 0);
        char buf[64] = {0};
        sio.socketReader->readFrame();
        sio.socketReader->read(buf, 64);
        sio.socketReader->readOne(buf, 64);
        std::cout << "[server response]" << buf << std::endl;
        return AUTO_CLOSE;
    }
    int Ping::serverAction(socketinf clientinf, unsigned long long dataLength) {
        // Auto generate
        SocketIO sio(clientinf);
        char buf[64] = "Hello,your ip is:";
        char ip[16];
        clientinf.getip(ip);
        strcat(buf, ip);
        sio.socketWriter->writeOne(buf, strlen(buf) + 1);
        sio.socketWriter->writeOne(buf, strlen(buf) + 1);
        return CONTINUE;
    }
}
